<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
		<link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
		<link rel="stylesheet" type="text/css"
			href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
		<script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>	
		<script type="text/javascript"
			src="<c:url value="/static/js/common.js"/>"></script>		
		<script>
		
			function initList(listDisplayEId) {
				$('#' + listDisplayEId).datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							onClickRow:function(rowIndex){
								$(".myrad").prop("checked",false);
								$(".myrad").eq(rowIndex).prop("checked",true);
								$('#listDisplay').datagrid('beginEdit', rowIndex);
							} ,
							toolbar : [
									
									{
										id : listDisplayEId + '_btn_edit',
										text : '审核通过',
										iconCls : 'icon-edit',
										handler : function() {
										
											var row = $('#'+listDisplayEId).datagrid('getSelections');
 											if(row.length == 0){
												$.messager.alert('提示','请选择一条记录操作！','info');
												return;
											}else{
												var str = "ordId="+row[0]['ordId'];	
												
												if(row[0]['ordState'] != 1){
													$.messager.alert('提示','所选择的状态不正确！','info');
													return;
												}
												
  												$.messager.confirm('提示', '是否审核通过该条记录？', function(r){
													if (r){			
														$.ajax({type:'post',url:"<c:url value='/order/passOrder.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
							 							success:function(data){
															if(data.success){
																$.messager.alert("提示", "审核成功！", 'info');
																$('#'+listDisplayEId).datagrid('reload');
															}else{
																$.messager.alert("提示", data.msg, 'warning');
															}
														},
														error:function(){
														$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
														}
														});
													} 
													$('#'+listDisplayEId).datagrid('reload');
													$('#'+listDisplayEId).datagrid('clearSelections');
												});
											}
											$('#'+listDisplayEId).datagrid('clearSelections');
										}
									},
									{
										id : listDisplayEId + '_btn_del',
										text : '审核未通过',
										iconCls : 'icon-edit',
										handler : function() {
										
											var row = $('#'+listDisplayEId).datagrid('getSelections');
 											if(row.length == 0){
												$.messager.alert('提示','请选择一条记录操作！','info');
												return;
											}else{
												
												var rowIndex=$('#'+listDisplayEId).datagrid('getRowIndex',row[0]['ordId']);
												$('#listDisplay').datagrid('endEdit', rowIndex);
												
												var str = "ordId="+row[0]['ordId']+"&reviewRemark="+row[0]['reviewRemark'];	
												
												if(row[0]['ordState'] != 1){
													$.messager.alert('提示','所选择的状态不正确！','info');
													return;
												}
												
  												$.messager.confirm('提示', '是否审核不通过该条记录？', function(r){
													if (r){			
														$.ajax({type:'post',url:"<c:url value='/order/nopassOrder.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
							 							success:function(data){
															if(data.success){
																$.messager.alert("提示", "审核未通过成功！", 'info');
																$('#'+listDisplayEId).datagrid('reload');
															}else{
																$.messager.alert("提示", data.msg, 'warning');
															}
														},
														error:function(){
														$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
														}
														});
													} 
													$('#'+listDisplayEId).datagrid('reload');
													$('#'+listDisplayEId).datagrid('clearSelections');
												});
											}
											$('#'+listDisplayEId).datagrid('clearSelections');
										}
									}],
							onLoadError:function(){
								$.messager.alert('错误','获取数据失败，请与管理员联系！','error');
							}
						
						});
				
			};
			$(document).ready(function() {
				initList('listDisplay');
			});
			function  goDetailedContent(val,rowData,rowIndex){
				return '<a href="#" onclick="constructionManager(\'' + rowData.ordId+ '\')">'+val+'</a>  '
			}
			
			function constructionManager(id) {
				var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/order/goSelectCustomDetailedForAdmin.do'/>"+"?id="+id,"sun","width=1200px,height=600px,status=no,scrollbars=yes");
				new_win.focus();
			
			}
			//下拉框
			$(function() {        
		        // 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		        $('#ordState').combobox({   
		            data:[{"ordState":"0","ordStateName":"全部"},{"ordState":"1","ordStateName":"待审核"},{"ordState":"2","ordStateName":"审核通过"},{"ordState":"3","ordStateName":"审核未通过"},{"ordState":"4","ordStateName":"不需审核"}],   
		            editable:false, //不可编辑状态  
		            cache: false,  
		            valueField:'ordState',     
		            textField:'ordStateName',  
		        });      
		    }); 
			
			function searchInfo(){
				if($('#ordState').combobox('getValue') ==''){
					$('#listDisplay').datagrid('load', {
						ordState : 0,
						ordDate : $('#ordDate').datebox('getValue'),
						ordCustName : $('#ordCustName').val()
					}); 
				}else{
					$('#listDisplay').datagrid('load', {
						ordState : $('#ordState').combobox('getValue'),
						ordDate : $('#ordDate').datebox('getValue'),
						ordCustName : $('#ordCustName').val()
					});  
				}
			}
			
		</script>
		</head>
		<body>
		<table width="98%">
		<tr><td>
			<div style="height: auto; width:1180px;background: #fafafa; padding: 5px;" class="easyui-panel" title="查询" iconCls="icon-search" collapsible="true" minimizable="false" maximizable="false" closable="false">
					<form id="searchForm" name="searchForm" method="post"
						action="userlist.txt"
						onsubmit="return searchDGData(this.id,'listDisplay');">
						<div>
		            	<table cellpadding="5">
								<tr>
								
									<td>审核状态：</td>
									<td><input class="easyui-combobox" id="ordState" editable="false" name="ordState"></input></td>
									<td>订单日期：</td>
									<td><input class="easyui-datebox" editable="true" id="ordDate" name="ordDate"></input></td>
									<td>客户名：</td>
									<td><input class="easyui-validatebox" id="ordCustName" editable="true" name="ordCustName"></input></td>
							            
		                    		<td><input type="button" onclick="searchInfo()" value="查询"></td>
		                    	</tr>
		                </table>					 
						</div>
					</form>
				</div>
			</td></tr>
		<tr style="height: 12px;"></tr>
		<tr>
		<td>
				<table id="listDisplay" title="我的订单列表" 
			iconCls="icon-list" singleSelect="true" idField="ordId"
			url="<c:url value="/order/reviewOrderList.do"/>" loadMsg="请稍候......"
			pagination="true" pageSize="20"
			pageList="[10,20,30,40,50,100,100]" sortName="foodId"
			rownumbers="true" sortOrder="asc">
			<thead>
				<tr>
				    <th field="id" width="25" align="center"  checkbox="true">
					</th> 
				    <th field="ordId" width="80"  sortable="true" >
						订单号
					</th>	
 					<th field="ordCustId" width="60" sortable="true" >
						客户ID
					</th>		
					<th field="ordCustName" width="80" sortable="true" >
						客户名
					</th>	
					<th field="ordState" width="100"  formatter="formatOrdState" sortable="true" >
						订单状态
					</th>	
					<th field="ordDate" width="100  sortable="true" >
						订单日期
					</th>	
					<th field="ordDay" width="80"  sortable="true" >
						订单日
					</th>
					<th field="ordValue" width="80"  sortable="true" align="right">
						菜品总价钱
					</th>
					<th field="reviewRemark" width="120" sortable="true" editor="text">
						审核原因
					</th>
					<th field="buySelfFlag" width="80" sortable="true" formatter="formateSuperSelf">采购模式
                    </th>
					<th field="submitOrdTimeLast" width="100" sortable="true">提交订单时间
                    </th>
					<th field="content" width="110" formatter="goDetailedContent" sortable="true" >
						查看订单详细内容
					</th>		
 				</tr>
			</thead>
			</table>
			</td>
			</tr>
		</table>
	</body>
</html>